/*
*	Project: Aethon
*
*	File: ModelPart.h
*
*	Author: Robert Whiting
*
*	Date: 2/11/2009
*
*	Purpose: The model part contains relative positions and rotations to display
*	objects other than the terrain. Each model may contain zero or more sub
*	model parts, thus forming a tree structure.
*/

#ifndef MODEL_PART_H_
#define MODEL_PART_H_

#include <iostream>
#include <GL/glut.h>
#include <fstream>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include "../include/vector3f.h"
using namespace std;

struct Material {
    string name;
    float amb;
    float spec[4];
    float diff[4];
    float shine;
};

struct Image {
    string name;
	int width;
	int height;
	int bpp;
	GLuint id;
	unsigned char *data;
};

class ModelPart{
	string name;
	int modelPartId;
	vector3f relativeRotation;
	vector3f relativePosition;
	std::vector<ModelPart*> modelPartList;
	Image texImage;
	
	public:
	ModelPart() {
	}
	
	void display(void);
	void load(string filename);
	double normal(const double a[3], const double b[3], const double c[3], double d[3]);
	vector<Material> readMaterials(string basefile);
	void setMaterial(string matName, vector<Material> &mats);
    int buildModelPart(string filename);
    void processObj(ifstream &in, vector<Material> &mats);
    void processImage(string filename);
    void loadTexture();
    void freeTexture();
	
	//gets and sets
	
	vector3f getRelativeRotation(){
		return relativeRotation;
	}
	void setRelativeRotation(vector3f v){
		relativeRotation = v;
	}
	
	vector3f getRelativePosition(){
		return relativePosition;
	}
	void setRelativePosition(vector3f v){
		relativePosition = v;
	}
	
	vector<ModelPart*> getModelPartList(){
		return modelPartList;
	}
	void setModelPartList(std::vector<ModelPart*> m){
		modelPartList = m;
	}
	
	int getModelPartId(){
		return modelPartId;
	}
	
	string getName(){
		return name;
	}
	
	int getTexID(){
        return texImage.id;
    }
};

#endif /*MODEL_PART_H_*/

